package com.zyh.kaoshi.test2;

/**
 * @Author zyh
 * @Date 2024/8/10 11:17
 * @Description
 */

public class Printer {
    private int index=1;
    public Printer() {
    }
    public synchronized void printNum(int i){//打印数字的方法
        if (index%3==0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(i);
        index++;
        this.notifyAll();
    }
    public synchronized void printZiMu(char c){//打印字母的方法
        if (index%3!=0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(c);
        index++;
        this.notifyAll();
    }
}
